package cn.itcast.nems.base.web.controller.o;


import cn.itcast.ic.common.bean.Page;
import cn.itcast.nems.base.api.SubjectApi;
import cn.itcast.nems.base.dto.SubjectDTO;
import cn.itcast.nems.base.dto.SubjectQueryDTO;
import cn.itcast.nems.common.PageQueryModel;
import cn.itcast.nems.common.web.vo.BasePageRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 学科
 * </p>
 *
 * @author zhouwei
 * @since 2023/9/5 4:59 PM
 **/
@RestController
@RequestMapping("/o/subject")
@RequiredArgsConstructor
public class SubjectController {
    private final SubjectApi subjectApi;

    /**
     * 学科分页查询
     * @param queryParam 请求参数
     * @return 分页结果
     */
    @PostMapping("/page/list")
    public ResponseEntity<?> findPageList(@RequestBody BasePageRequest<SubjectQueryDTO> queryParam) {
        queryParam.convert();
        SubjectQueryDTO queryDTO = Objects.nonNull(queryParam.getCondition()) ? queryParam.getCondition(): new SubjectQueryDTO() ;
        queryParam.setCondition(queryDTO);
        PageQueryModel<SubjectQueryDTO> queryModel =new PageQueryModel<>(queryParam.getPageNumber(), queryParam.getPageSize() , queryDTO) ;
        Page<SubjectDTO> page  =   subjectApi.findPageList(queryModel) ;
        return ResponseEntity.ok().body(page) ;
    }
    /**
     * 获取校区列表
     *
     * @return 响应正文
     */
    @RequestMapping("/list")
    public ResponseEntity<?> list(String model) {
        List<?> list = subjectApi.findSubjectsByTeachingModel(model ,true);
        return ResponseEntity.ok().body(list);
    }

}
